package org.ajax.common;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AjaxMap<T> {
	
	private T param;
	
	
	private static AjaxMap ajaxMap;
	
	private AjaxMap(T param2)
	{
		this.param = param2;
	}

	
	public T getParam() {
		return param;
	}

	/**
	 * @param param
	 * @return
	 */
	public static <T> AjaxMap<T> getInstance(T param) {
		
		if (ajaxMap == null) {
			synchronized (AjaxMap.class){
                if(ajaxMap == null){
                	ajaxMap = new AjaxMap<T>(param);
                } else {
        			ajaxMap.setParam(param);
        		}
			}
		} else {
			ajaxMap.setParam(param);
		}
		return ajaxMap;
	}
	
	
	/**
	 * @param param2
	 */
	public void setParam(T param2) {
		// TODO Auto-generated method stub
		this.param = param2;
	}
	
	public Map<String, Object> getAjaxResultByMap()
	{
		int status = this.param == null ? 0x00 : 0x01;
		
		String message = this.param == null ? "失败" : "成功";
		
		Map<String, Object> json = new HashMap<String, Object>();
		
		json.put("status", status);
		
		json.put("message", message);
		
		json.put("data", this.param);
		
		return json;
	}
	
	

	public T getResult() {
		return this.param;
	}

	public void setResult(T result) {
		this.param = result;
	}
	
}
